<html>
<head><meta charset="utf-8"><title>where T: ZST · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html">where T: ZST</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212547786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212547786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212547786">(Oct 07 2020 at 12:05)</a>:</h4>
<p>Is it possible to express this bound, perhaps using const generics?</p>



<a name="212548033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212548033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212548033">(Oct 07 2020 at 12:08)</a>:</h4>
<p>ZST should be an auto trait like Send or Sync, if we add it</p>



<a name="212548114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212548114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212548114">(Oct 07 2020 at 12:09)</a>:</h4>
<p>Well <code>mem::size_of()</code> is const, so I figured it might be possible to bound on it, but I get the error <code>error: constant expression depends on a generic parameter</code></p>



<a name="212548287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212548287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212548287">(Oct 07 2020 at 12:11)</a>:</h4>
<p>what I mean is that ZST types usually have some determined constructs.<br>
an auto trait that auto-implemented for those constructs is nice.</p>



<a name="212548619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212548619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212548619">(Oct 07 2020 at 12:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="295632">Diggory Blake</span> <a href="#narrow/stream/122651-general/topic/where.20T.3A.20ZST/near/212548114">said</a>:</p>
<blockquote>
<p>Well <code>mem::size_of()</code> is const, so I figured it might be possible to bound on it, but I get the error <code>error: constant expression depends on a generic parameter</code></p>
</blockquote>
<p>The <code>const_evaluatable_checked</code> feature might help, but it is a hard problem to implement.<br>
An auto-trait is easier to implement, but it is a T-lang issue.</p>



<a name="212548909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212548909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212548909">(Oct 07 2020 at 12:17)</a>:</h4>
<p>Something like this maybe? <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=ee83789c748745b2d8d66dfafc145fb9">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=ee83789c748745b2d8d66dfafc145fb9</a></p>



<a name="212548924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212548924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212548924">(Oct 07 2020 at 12:17)</a>:</h4>
<p>It's not quite what you want I believe unfortunately</p>



<a name="212549764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212549764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212549764">(Oct 07 2020 at 12:23)</a>:</h4>
<p>I got it working using <code>const_evaluatable_unchecked</code>: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=fdc3700a12f8f7fd321ea239b005df35">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=fdc3700a12f8f7fd321ea239b005df35</a></p>



<a name="212549881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212549881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212549881">(Oct 07 2020 at 12:24)</a>:</h4>
<p>(if you change y -&gt; x, or switch to <code>p</code>, it compiles)</p>



<a name="212581417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212581417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212581417">(Oct 07 2020 at 16:06)</a>:</h4>
<p>Can you elaborate on <em>why</em> you want to bound on ZST?  That said, the safe transmute work will probably make it possible to bound on <code>T: SomeBikeshed&lt;()&gt;</code> that will probably be good enough.</p>
<p>Most code right now just checks it dynamically, since it's trivially optimized away for non-ZST so there's no runtime or binary size cost.</p>



<a name="212591848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212591848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212591848">(Oct 07 2020 at 17:27)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> see <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/250">https://github.com/rust-lang/unsafe-code-guidelines/issues/250</a> and <a href="https://github.com/rust-lang/rfcs/issues/3000">https://github.com/rust-lang/rfcs/issues/3000</a> for context</p>



<a name="212591901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212591901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212591901">(Oct 07 2020 at 17:27)</a>:</h4>
<p>I'm probably going to continue to rely on a dynamic assert for now, at least when on stable rust</p>



<a name="212618248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212618248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212618248">(Oct 07 2020 at 20:58)</a>:</h4>
<p>The ability to write this bound would make going from ZST -&gt; non-ZST in a library a breaking change, do we want that?</p>



<a name="212619113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212619113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212619113">(Oct 07 2020 at 21:05)</a>:</h4>
<p>it already is a breaking change (for you can <code>assert_eq!(size_of::&lt;T&gt;(), 0)</code>) or whatever, for some definition of breaking change.</p>



<a name="212619208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212619208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212619208">(Oct 07 2020 at 21:06)</a>:</h4>
<p>or an equivalent <code>static_assert</code>.</p>



<a name="212619319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212619319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212619319">(Oct 07 2020 at 21:07)</a>:</h4>
<p>Much like inference failures introduced by addition of additional implementations this is not broadly considered an actual reason to bump the major version though.</p>



<a name="212621683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212621683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212621683">(Oct 07 2020 at 21:28)</a>:</h4>
<p>yeah I mean, it's definitely a gray area</p>



<a name="212621826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212621826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212621826">(Oct 07 2020 at 21:30)</a>:</h4>
<p>I think introducing a trait could mean more people expect it to be a breaking change</p>



<a name="212621889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212621889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212621889">(Oct 07 2020 at 21:31)</a>:</h4>
<p>maybe that's solvable with documentation</p>



<a name="212622010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212622010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212622010">(Oct 07 2020 at 21:32)</a>:</h4>
<p>but this would be the first trait in std that I know of whose impls are not guaranteed to hold in the future</p>



<a name="212622016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212622016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212622016">(Oct 07 2020 at 21:32)</a>:</h4>
<p>which is something</p>



<a name="212622097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212622097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212622097">(Oct 07 2020 at 21:33)</a>:</h4>
<p>With const generics, can't you have the trait be <code>where T: Size&lt;0&gt;</code>?</p>



<a name="212623046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212623046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212623046">(Oct 07 2020 at 21:43)</a>:</h4>
<p>if a type has any private fields or is non-exhaustive, <code>size_of</code> should be considered a private detail</p>



<a name="212627186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/where%20T%3A%20ZST/near/212627186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/where.20T.3A.20ZST.html#212627186">(Oct 07 2020 at 22:30)</a>:</h4>
<p>yeah, that sounds exactly right to me!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>